/**
 * Crea al personaje Sonic2.
 * @constructor
 * @param {Number} x - pos x.
 * @param {Number} y - pos y.
 * @param {Number} w - anchura.
 * @param {Number} h - altura.
 * @param {Number} rx - punto de registro de objeto x.
 * @param {Number} ry - punto de registro de objeto y.
 * @param {Number} sx - escala de objeto x.
 * @param {Number} sy - escala de objeto y.
 */
Sonic2 = function(x, y, w, h, rx, ry, sx, sy, imgId) {
    w = w || 40;
    h = h || 40;
    rx = rx || 20;
    ry = ry || 20;
    sx = sx || 1;
    sy = sy || 1;

    this.animation = null;
    GameObject.call(this, x, y, w, h, rx, ry, sx, sy);
    this.facingRight = true;
    this.currAnimationName = "";
    this.imgId = imgId || "sonicWalkJump";
};

Sonic2.prototype = Object.create(GameObject.prototype);

Sonic2.prototype.loadAnimations = function() {
    var redImg = GameSys.imgLoader.loadedImages[this.imgId];
    var walkSlowdownFactor = 5;
    var jumpSlowdownFactor = 3;

    // create spritesheet and assign the associated data.
    var spriteSheet = new createjs.SpriteSheet({
        //image to use
        images: [redImg],
        //width, height & registration point of each sprite
        frames: {
            width: this.w,
            height: this.h,
            regX: this.rx,
            regY: this.ry
        },
        // To slow down the animation loop of the sprite, we set the frequency to 4 to slow down by a 3x factor
        animations: {
            walk_r: [0, 7, "walk_r", walkSlowdownFactor],
            walk_l: [8, 15, "walk_l", walkSlowdownFactor],
            jump_r: [16, 19, "jump_r", jumpSlowdownFactor],
            jump_l: [20, 23, "jump_l", jumpSlowdownFactor],
            idle_r: [7, 7, "idle_r", jumpSlowdownFactor],
            idle_l: [8, 8, "idle_l", jumpSlowdownFactor]
        }
    });
    this.spriteSheet = spriteSheet;


    // create a BitmapSequence instance to display and play back the sprite sheet:
    var bmpAnimation = new createjs.BitmapAnimation(spriteSheet);
    /*de la siguiente manera es posible escalar una animacion*/
    bmpAnimation.scaleX = this.sx;
    bmpAnimation.scaleY = this.sy;

    // set the registration point (the point it will be positioned and rotated around)
    // to the center of the frame dimensions:
    bmpAnimation.regX = bmpAnimation.spriteSheet.frameWidth / 2 | 0;
    bmpAnimation.regY = bmpAnimation.spriteSheet.frameHeight / 2 | 0;
    //bmpAnimation.regX = 0;
    //bmpAnimation.regY = 0;

    bmpAnimation.gotoAndPlay("walk_d");

    // set up a shadow. Note that shadows are ridiculously expensive. You could display hundreds
    // of animated rats if you disabled the shadow.
    bmpAnimation.shadow = new createjs.Shadow("#454", 0, 5, 4);

    bmpAnimation.name = "sonicWalkJump";

    // have each monster start at a specific frame
    bmpAnimation.currentFrame = 0;

    this.animation = bmpAnimation;

    this.update();
};
//loadAnimations
